﻿function Online_Useraction()
{                   
    this.intervalTime = 15;//函数执行时间间隔(秒)
    this.sendIntervalTime = 90; //发送时间间隔(秒)
    this.receiveUrl="http://online.my.yaolan.com/interface/action.ashx"; 
    this.flagCookieName = "yaolan_useronline_sendflag";
    this.flagCookieValue = "1";
    this.userCookieName = "user_id";
    
    function SendNotice()
    {
        //check login
        var userValue=getCookieNoEscape(userCookieName);
        if(userValue==null)
        {
            return;
        }
        //check flagcookie
        if(getCookie(flagCookieName)!=null)
        {   return;
        }
        else
        {
            //sendmessage
            var now = new Date();
            var sendImg = new Image(); 
            sendImg.src = receiveUrl + "?u=" + userValue + "&t=" + now.getTime();
            SetCookie(flagCookieName,flagCookieValue,sendIntervalTime);    
        }
    }   
    SendNotice();                     
    //cookie functions
    function SetCookie(name, value,expTime)
    {
        var exp  = new Date();
        exp.setTime(exp.getTime() + expTime*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString() + ";path=/;" + "domain=yaolan.com;";
    }
    function getCookie(name)
    {
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        if(arr != null) return unescape(arr[2]); return null;
    } 
    function getCookieNoEscape(name)
    {
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        if(arr != null) return arr[2]; return null;
    } 
}
Online_Useraction();
setInterval(Online_Useraction,intervalTime*1000);